home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / src / asm / depack.asm next >
Encoding:
Assembly Source File  |  2001-12-15  |  2.0 KB  |  121 lines

  1. ;;
  2. ;; aPLib compression library  -  the smaller the better :)
  3. ;;
  4. ;; TASM / MASM / WASM assembler depacker
  5. ;;
  6. ;; Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7. ;; All Rights Reserved
  8. ;;
  9.  
  10. .386p
  11. .MODEL flat
  12.  
  13. .CODE
  14.  
  15. PUBLIC _aP_depack_asm
  16.  
  17. _aP_depack_asm:
  18.     pushad
  19.  
  20.     mov    esi, [esp + 36]    ; C calling convention
  21.     mov    edi, [esp + 40]
  22.  
  23.     cld
  24.     mov    dl, 80h
  25.  
  26. literal:
  27.     movsb
  28. nexttag:
  29.     call   getbit
  30.     jnc    literal
  31.  
  32.     xor    ecx, ecx
  33.     call   getbit
  34.     jnc    codepair
  35.     xor    eax, eax
  36.     call   getbit
  37.     jnc    shortmatch
  38.     inc    ecx
  39.     mov    al, 10h
  40. getmorebits:
  41.     call   getbit
  42.     adc    al, al
  43.     jnc    getmorebits
  44.     jnz    domatch
  45.     stosb
  46.     jmp    short nexttag
  47. codepair:
  48.     call   getgamma_no_ecx
  49.     dec    ecx
  50.     loop   normalcodepair
  51.     call   getgamma
  52.     jmp    short domatch_lastpos
  53.  
  54. shortmatch:
  55.     lodsb
  56.     shr    eax, 1
  57.     jz     donedepacking
  58.     adc    ecx, ecx
  59.     jmp    short domatch_with_2inc
  60.  
  61. normalcodepair:
  62.     xchg   eax, ecx
  63.     dec    eax
  64.     shl    eax, 8
  65.     lodsb
  66.     call   getgamma
  67.     cmp    eax, 32000
  68.     jae    domatch_with_2inc
  69.     cmp    ah, 5
  70.     jae    domatch_with_inc
  71.     cmp    eax, 7fh
  72.     ja     domatch_new_lastpos
  73.  
  74. domatch_with_2inc:
  75.     inc    ecx
  76.  
  77. domatch_with_inc:
  78.     inc    ecx
  79.  
  80. domatch_new_lastpos:
  81.     xchg   eax, ebp
  82. domatch_lastpos:
  83.     mov    eax, ebp
  84.  
  85. domatch:
  86.     push   esi
  87.     mov    esi, edi
  88.     sub    esi, eax
  89.     rep    movsb
  90.     pop    esi
  91.     jmp    short nexttag
  92.  
  93. getbit:
  94.     add     dl, dl
  95.     jnz     stillbitsleft
  96.     mov     dl, [esi]
  97.     inc     esi
  98.     adc     dl, dl
  99. stillbitsleft:
  100.     ret
  101.  
  102. getgamma:
  103.     xor    ecx, ecx
  104. getgamma_no_ecx:
  105.     inc    ecx
  106. getgammaloop:
  107.     call   getbit
  108.     adc    ecx, ecx
  109.     call   getbit
  110.     jc     getgammaloop
  111.     ret
  112.  
  113. donedepacking:
  114.     sub    edi, [esp + 40]
  115.     mov    [esp + 28], edi    ; return unpacked length in eax
  116.  
  117.     popad
  118.     ret
  119.  
  120. END
  121.